$user=$('#user').val();
if($user===""){
    layer.msg("您还没有登陆哦！");
    window.location.href="login.html";

}
function xiuGai(){
    window.location.href="update.php";

}
$.ajax({
    type: 'post',
    cache: false,
    url: '../php/admin/select_taskAll.php',
    data: {
        "user":$user,
    },
    dataType: 'json',
    success: function (data) {
        $coun = data.count;
        $dat = data.data;
        $notice=$dat[0].task_content;
        var not=document.getElementById("user_notice");
        not.innerHTML=$notice;
        for ($i = 0; $i < $coun; $i++) {
            $id = $dat[$i].id;
            $user = $dat[$i].task_admin;
            $title=$dat[$i].title;
            $time=$dat[$i].time_over;
            $task_a=$dat[$i].task_a;
            $user_a=$dat[$i].user_a;;
            $remark=$dat[$i].remark;
            $content=$dat[$i].task_content;
            $addtime=$dat[$i].task_time;
            $url=$dat[$i].url;
            $complete=$dat[$i].complete;

            $li = $("<div id="+$id+" class=\"layui-card\" id=\"card\">\n" +"<hr class=\"layui-bg-red\">"+
                "<div class=\"layui-card-header\">"+"任务详情："+"<button id='file' class=\"layui-btn layui-btn-xs\" >"+"<a href='"+$url+"' download='file' style='color: white'>"+"附件下载"+"</a>"+"</button>"+"<a id='overTime'>"+"任务截至时间："+$time+"</a>"+"<a id='overTime'>"+"完成时间："+$complete+"</a>"+"</div>" +
                "                    <div class=\"layui-card-body\">\n" +$content+"<br>" +
                "<hr>"+"<div class=\"layui-card-header\">"+"任务："+"<a id='overTime'>"+"接受任务的成员："+$user_a+"</a>"+"</div>"+
                $task_a+
                "<hr>"+"<div class=\"layui-card-header\">"+"备注："+"</div>"+
                $remark+"<br>"+
                "                       <span id=\"time\">"+ "发布时间："+$addtime+"&nbsp;|&nbsp;"+"发布人："+$user+"</span>" +
                "                          <br>\n" +
                "                    </div>\n" +
                "                </div>");
            $("#uul").append($li);

        }
    },
    error: function (data) {
        layer.msg("暂无任务");
    }
});



$.ajax({
    type: 'post',
    cache: false,
    url: '../php/admin/select_notice.php',
    data: {
        "user":$user,
    },
    dataType: 'json',
    success: function (data) {
        $dat = data.data
        $coun = data.count;
        $notice=$dat[0].content;
        var not=document.getElementById("notice"),
            user_not=document.getElementById("user_task");
        not.innerHTML=$notice;
        user_not.innerHTML=$notice;

        for ($i = 0; $i < $coun; $i++) {
            $id = $dat[$i].id;
            $user = $dat[$i].no_admin;
            $title=$dat[$i].title;
            $content=$dat[$i].content;
            $addtime=$dat[$i].no_addtime;
            var date=new Date(parseInt($addtime)*1000);
            Y=date.getFullYear()+'年';
            M=(date.getMonth()+1<10?'0'+(date.getMonth()+1):date.getMonth()+1)+'月';
            D=date.getDate()+'日';
            h=date.getHours()+':';
            m=date.getMinutes()+':';
            s=date.getSeconds();
            $date=Y+M+D+h+m+s;
            if($i===0){
                $li = $(" <li class=\"layui-timeline-item\">\n" +
                    "                        <i class=\"layui-icon layui-timeline-axis\"></i>\n" +
                    "                        <div class=\"layui-timeline-content layui-text\">\n" +
                    "                            <div class=\"layui-timeline-title\">"+$date+"&nbsp;&nbsp;"+"主题："+$title+"&nbsp;&nbsp;内容："+$content+"</div>\n" +
                    "                        </div>\n" +
                    "                    </li>");
            }
            else if($i===$coun-1) {
                $li = $(" <li class=\"layui-timeline-item\">\n" +
                    "<i class=\"layui-icon layui-anim layui-anim-rotate layui-anim-loop layui-timeline-axis\"></i>"+
                    "                        <div class=\"layui-timeline-content layui-text\">\n" +
                    "                            <div class=\"layui-timeline-title\">" + $date + "&nbsp;&nbsp;" + "主题：" + $title + "&nbsp;&nbsp;内容：" + $content + "</div>\n" +
                    "                        </div>\n" +
                    "                    </li>");

            }
            else {
                $li = $(" <li class=\"layui-timeline-item\">\n" +
                    "<i class=\"layui-icon layui-timeline-axis\"></i>"+
                    "                        <div class=\"layui-timeline-content layui-text\">\n" +
                    "                            <div class=\"layui-timeline-title\">" + $date + "&nbsp;&nbsp;" + "主题：" + $title + "&nbsp;&nbsp;内容：" + $content + "</div>\n" +
                    "                        </div>\n" +
                    "                    </li>");

            }
            $("#notice-list").append($li);
        }


    },
    error: function (data) {
        layer.msg("暂无公告");
    }
});
//获取管理员的信息
var user=document.getElementById("user").value;
$.ajax({
    type: 'post',
    cache: 'false',
    url: '../php/admin/select_admin.php',
    data: {
        "user":user,
    },
    dataType: 'Json',
    success: function (dat) {
        var user_name=document.getElementById("user_name"),
            user_tel=document.getElementById("user_tel"),
            user_email=document.getElementById("user_email"),
            user_class=document.getElementById("user_class"),
            headImg=document.getElementById("headImg"),
            code=document.getElementById("code"),
            email=document.getElementById("QQemail");

        $dat=dat.data[0];
        email.value=$dat.email;
        user_class.innerHTML=$dat.className;
        user_tel.innerHTML=$dat.tel;
        user_email.innerHTML=$dat.email;
        user_name.innerHTML=$dat.user;
        code.innerHTML=$dat.code;
        headImg.src=dat.data[0].img;
    },
    error: function (dat) {
        layer.msg("请检查网络是否正常");
    }


});
function out() {
    layer.confirm('真的要退出吗？', function(index) {
        window.location.href="../php/user/clearSession.php";
    })
}
function updateEmail() {
    var qqEmail=document.getElementById("QQemail").value,
        emailCode=document.getElementById("serverCode").value;
    if(qqEmail==="" ){
        layer.msg("保存失败，你的邮箱没有填");
        return false;
    }
    if(emailCode===""){
        layer.msg("保存失败，你的授权码没有填");
        return false;

    }
    else {
        $.ajax({
            type:'post',
            cache:'false',
            url:'../php/admin/admin_update_email.php',
            data:{
                "user":$user,
                "email":qqEmail,
                "emailCode":emailCode,
            },
            dataType:'json',
            success:function (dat) {
                layer.msg(dat.message);
            },
            error:function () {
                layer.msg("保存失败，未修改任何数据");
            },

        })

    }
}